package org.warehouse.dao.engine;


public class DataObject<T> {
	private final Class<T> type;
	
	private final T data;
	
	private DataObject(Class<T> type, T data) {
		this.type = type;
		this.data = data;
	}

	public Class<T> getType() {
		return type;
	}

	@SuppressWarnings({ "unchecked", "hiding" })
	public <T> T getData() {
		return (T) data;
	}
	
	@SuppressWarnings("unchecked")
	public static <T> DataObject<T> of(T data) {
	    if (data == null) {
	        return new DataObject<T>((Class<T>) Object.class, null);
	    } else {
	        return new DataObject<T>((Class<T>) data.getClass(), data);
	    }
	}
	
	@Override
	public String toString() {
	    return getData().toString();
	}
	
}
